﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Coffee_Restaurant.Models
{
    class ValidateHelper
    {
        public static bool IsString(string inputData, int minlength)
        {
            const string pattern = @"^[a-zA-Z0-9\s\w*]+$";
            const RegexOptions regexOptions = RegexOptions.Singleline;
            var regex = new Regex(pattern, regexOptions);
            if (regex.IsMatch(inputData) && inputData.Length >= minlength)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// check bool decimals
        /// </summary>
        /// <param name="inputData"></param>
        /// <param name="minlength"></param>
        /// <returns>true false</returns>
        public static bool IsNumberOrDecimals(string inputData, int minlength)
        {
            const string pattern = @"\d+$";
            const RegexOptions regexOptions = RegexOptions.Singleline;
            var regex = new Regex(pattern, regexOptions);
            if (regex.IsMatch(inputData) && inputData.Length >= minlength)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// return String.Format("{0:0,0}", decimalPrice)
        /// </summary>
        /// <param name="inputData"></param>
        /// <returns>String.Format("{0:0,0}", decimalPrice)</returns>
        public static string TryParseDecimal(string inputData)
        {
            decimal decimalPrice;
            if (decimal.TryParse(inputData, out decimalPrice))
            {
                return String.Format("{0:0,0}", decimalPrice);
            }
            return "";
        }

        public static decimal GetValueTryParseDecimal(string inputData)
        {
            decimal decimalValue;
            if (decimal.TryParse(inputData, out decimalValue))
            {
                return decimalValue;
            }
            return 0;
        }

        public static int GetValueTryParseInt(string inputData)
        {
            int intValue;
            if (int.TryParse(inputData, out intValue))
            {
                return intValue;
            }
            return 0;
        }

        public static int CountLength(string inputData)
        {
            return inputData.Length;
        }

    }


}
